#! /bin/bash
check_results=`nvm ls`
get_version=`node -v`
check_version="17.0.0"
run_cmd="nr --filter @zlyun-vue/documentation dev"

# echo "command(nvm ls) results are: $check_results"
echo "$get_version"
echo "$check_version"
if [[ $get_version =~ $check_version ]]
then
    echo "ok"
    # $check_results
    $run_cmd
    exit
fi

if [ $? -eq 0 ]
then
    echo "检查node版本... "
else
    echo "先请安装nvm"
    exit
fi

result=$(echo $check_results | grep "${check_version}")
# echo "$result"
if [[ "$result" != "" ]]
then
    echo "已下载$check_version直接切换"
    nvm use ${check_version}
    # echo "$get_version"
else
    echo "没有下载$check_version请手动下载 请执行nvm install $check_version"
    exit
fi
# echo pwd
$run_cmd

